package com.aaa.controller.scl;

import com.aaa.entity.LayData;
import com.aaa.entity.MyPage;
import com.aaa.entity.scl.SclPlane;
import com.aaa.entity.User;
import com.aaa.service.scl.SclPlaneService;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * (SclPlane)表控制层
 *
 * @author makejava
 * @since 2022-10-27 19:11:05
 */
@RestController
@RequestMapping("sclPlane")
public class SclPlaneController {
    /**
     * 服务对象
     */
    @Autowired
    private SclPlaneService sclPlaneService;

    // 查询所有的执行计划
    @GetMapping("queryAll")
    public LayData queryAll(MyPage myPage){
        return new LayData(sclPlaneService.queryAll(myPage));
    }

    @PostMapping
    public LayData checkCode(SclPlane plane){
        return new LayData(sclPlaneService.selectPlane(plane));
    }

    /**
     * 添加计划
     * @param plane
     * @param session
     * @return
     */
    @PostMapping("addPlane")
    public LayData addPlane(SclPlane plane, HttpSession session){
        User user1=(User) session.getAttribute("user");
        plane.setCreatetime(new Date());
        plane.setUid(user1.getId());
        System.out.println("plane = " + plane);
        return new LayData(sclPlaneService.insertPlane(plane));
    }

    /**
     * 查询邀请码
     * @param sclPlane
     * @return
     */
    @GetMapping("getByCode")
    public LayData queryByQyCode(SclPlane sclPlane){
        return new LayData(sclPlaneService.queryByQyCode(sclPlane));
    }

}

